package lc04;

import org.junit.jupiter.api.Test;

import java.util.Arrays;

/**
 * @Author Stringzhua
 * @Date 2024/4/20 21:39
 * description:
 */
public class test04 {
    //无序数组合并,复制元素方式1
    @Test
    public double[] findMedianSortedArrays(int[] nums1, int[] nums2) {
        double[] array = new double[nums1.length + nums2.length];
        int i = 0;
        for (int k = 0; k < nums1.length; k++, i++) {
            array[i] = nums1[k];
        }
        for (int j = 0; j < nums2.length; j++, i++) {
            array[i] = nums2[j];
        }
        Arrays.sort(array);
        int mid = array.length / 2;
        if (array.length % 2 == 0) {
            return new double[]{((array[mid - 1] + array[mid]) / 2.0)};
        } else {
            return new double[]{array[mid]};
        }
    }

    public static void main(String[] args) {
        int[] nums1 = {1, 3};
        int[] nums2 = {2};
        test01 test01 = new test01();
        double[] array = test01.findMedianSortedArrays(nums1, nums2);
        System.out.println(Arrays.toString(array));
    }
}

